﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ChatIBOXClient
{
	/// <summary>
	/// Interaction logic for SignInControl.xaml
	/// </summary>
	public partial class SignInControl : UserControl
	{
        private ServiceReference.Client _currentClient = null;

        public ServiceReference.Client CurrentClient
        {
            get
            {
                return _currentClient;
            }
            set
            {
                _currentClient = value;
            }
        }

        private static readonly RoutedEvent ButtonSignInClickEvent = EventManager.RegisterRoutedEvent("ButtonSignInClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SignInControl));
        private static readonly RoutedEvent ButtonLoginClickEvent = EventManager.RegisterRoutedEvent("ButtonLoginClick", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(SignInControl));

        public event RoutedEventHandler ButtonSignInClick
        {
            add
            {
                AddHandler(ButtonSignInClickEvent, value);
            }
            remove
            {
                RemoveHandler(ButtonSignInClickEvent, value);
            }
        }

        public event RoutedEventHandler ButtonLoginClick
        {
            add
            {
                AddHandler(ButtonLoginClickEvent, value);
            }
            remove
            {
                RemoveHandler(ButtonLoginClickEvent, value );
            }
        }

		public SignInControl()
		{
			this.InitializeComponent();
            this.textboxName.Focus();
		}

        private void buttonSingin_Click(object sender, RoutedEventArgs e)
        {
            //textboxPwd.Password = textboxName.Text ;
            _currentClient = new ChatIBOXClient.ServiceReference.Client();
            _currentClient.Name = textboxName.Text.ToString();
            RaiseEvent(new RoutedEventArgs(ButtonSignInClickEvent));
        }

        public void ProxySingleton_ProxyCallbackEvent(object sender, ProxyCallbackEventArgs e)
        {
            this.textboxPwd.Password = e.message.Content;
        }

        private void buttonLogin_Click(object sender, RoutedEventArgs e)
        {
            _currentClient = new ChatIBOXClient.ServiceReference.Client();
            _currentClient.Name = textboxName.Text.ToString();
            RaiseEvent(new RoutedEventArgs(ButtonLoginClickEvent));
        }
	}
}